<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>익명게시판</title>
<!-- 탑 인클루드 -->
<jsp:include page="/main/header.jsp"></jsp:include>
<%@ page import="com.popcorn.aboard.controller.*" %>
<%@ page import="com.popcorn.aboard.dao.*" %>
<%@ page import="com.popcorn.aboard.model.*" %>
<%@ page import="java.util.*" %>
<link rel="stylesheet" type="text/css" href="../css/reset.css" />
<link rel="stylesheet" type="text/css" href="../css/common.css" />
<link rel="stylesheet" type="text/css" href="../css/index.css" />
<script type="text/javascript">
function pageload(btn){
	var page = document.getElementById("pageidx").value;
	var last = document.getElementById("lastpage").value;
	if(btn.value=="이전페이지")
		page--;
	else if(btn.value=="다음페이지")
		page++;
	if(page == 0) page = 1;		
	if(page-1 == last) page--;
	
	window.location.href = 'AboardListDB.go?page='+page;
}
</script>
<%
	String pageNumberStr = request.getParameter("page");
	int pageNumber = 1;
	if (pageNumberStr != null) {
	    pageNumber = Integer.parseInt(pageNumberStr);
	} // 초기 페이지 및 선택시 선택된 페이지 설정
	List list = (List) request.getAttribute("Aboardlist");
	%>
<body >
<br><br><br><br><br><br><br><br><br>
<div class="wrap">

	<h1>익명게시판</h1>
	<br><br>
	<div class="table" >
		<table>
			<colgroup>
				<col width="10%" />
				<col width="*" />
				<col width="10%" />
				<col width="10%" />
			</colgroup>
			<thead>
				<tr>
					<th>No.</th>
					<th>제목</th>
					<th>등록날짜</th>
					<th>조회 수</th>	
				</tr>
			</thead>
			<tbody>
<%
	if(list != null){
		AboardModel model;
		if(pageNumber==1){
			for(int i=0; i<10; i++){
				if(i>=list.size()) break;
				model = (AboardModel) list.get(i);
				%>
			    <tr>
			        <td> <%= model.getSEQ_BBS() %> </td>
			        <td> <a href="AboardDetailDB.go?idx=<%=model.getSEQ_BBS()%>"><%= model.getTITLE() %></a></td>
			        <td> <%= model.getREG_DTM() %> </td>
			        <td> <%= model.getHIT_CNT() %> </td>		     
			    </tr>
			<%				
			}
			if(list.size()==0){ %>
			<tr><td colspan="6" align="center"> 등록된 글이 없습니다. </td></tr>
			<%
			}
		}else{
	        for(int i=10*(pageNumber-1); i< pageNumber*10; i++){
	        	if(i>=list.size()) break;
	        	model = (AboardModel) list.get(i);
%>

        <tr>
	        <td> <%= model.getSEQ_BBS() %> </td>
	        <td> <%= model.getTITLE() %> </td>
	        <td> <%= model.getREG_DTM() %> </td>
	        <td> <%= model.getHIT_CNT() %> </td>		     
		</tr>
<% 			}
        if(list.size()==0){ %>
		<tr><td colspan="6" align="center"> 등록된 글이 없습니다. </td></tr>
		<%
		}
	}
}else{ 
%>
    <tr><td colspan="6" align="center"> 등록된 글이 없습니다. </td></tr>
<% }
%>
</tbody>
</table>
<p align="center" style="margin-top: 10px;">
<input type="button" value="이전페이지" onclick="pageload(this)" >
<% 
	if(list != null){
		for(int j=0; j< (int)(list.size()/10+1); j++){%>
			<font style="line-height: 20px;">&nbsp;<a href="AboardListDB.go?page=<%=j+1%>"><%=j+1%></a>&nbsp;</font>
<%		}
	} 
%>
<input type="button" value="다음페이지" onclick="pageload(this)">
<input type="hidden" id="pageidx" name="pageidx" value="<%=pageNumber%>">
<input type="hidden" id="lastpage" name="lastpage" value="<%=(int)(list.size()/10+1)%>">
<br>
</p>
<p align="center">		
<a href="AboardInsert.jsp"><input type="button" value="글쓰기" style="margin-top: 10px;"></a></p>
</div></div>
<jsp:include page="../main/footer.jsp"></jsp:include>
</body>
</html>